﻿namespace LitFramework
{
    public class GameState_HotUpdate : IState
    {
        private StateMechine assetStateMechine;

        public StateMechine Master { get; set; }

        public void OnEnter(params object[] values)
        {
            assetStateMechine = new StateMechine();
            AssetState_Init assetState_Init = new AssetState_Init();
            assetStateMechine.AddState(assetState_Init);
            AssetState_UpdateVersion assetState_UpdateVersion = new AssetState_UpdateVersion();
            assetStateMechine.AddState(assetState_UpdateVersion);
            AssetState_UpdateManifest assetState_UpdateManifest = new AssetState_UpdateManifest();
            assetStateMechine.AddState(assetState_UpdateManifest);

#if UNITY_WECHAT_GAME
            var assetState_DownloadFiles = new AssetState_DownloadFiles_WxMiniGame();
#else
            var assetState_DownloadFiles = new AssetState_DownloadFiles();
#endif
            assetStateMechine.AddState(assetState_DownloadFiles);

            AssetState_ClearCache assetState_ClearCache = new AssetState_ClearCache();
            assetStateMechine.AddState(assetState_ClearCache);
            AssetState_UpdateOver assetState_UpdateOver = new AssetState_UpdateOver();
            assetState_UpdateOver.onUpdateOver = () =>
            {
                //资源更新完成
                SingletonManager.Instance.CreateSingleton<AssetManager>();
                Master.TurnToState<GameState_Hybrid>();
                assetStateMechine.Stop();
            };
            assetStateMechine.AddState(assetState_UpdateOver);

            assetStateMechine.Start<AssetState_Init>();
        }

        public void OnUpdate()
        {
            assetStateMechine.Update();
        }

        public void OnExit()
        {

        }
    }
}